package service;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/demo4")
public class ServletDemo4 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*获取请求参数的通用方式*/
        /*1.getParameter(String name)根据参数名称获取参数值
        * */
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username);
        System.out.println(password);
        /*根据参数名称获取参数值的数组*/
        String[] hobbies = req.getParameterValues("hobby");
        for (String hobby:hobbies){
            System.out.println(hobby);
        }
        /*获取请求转发器对象*/
        /*void setAtt*/
        req.setAttribute("uname",username);
        req.setAttribute("pwd",password);
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/demo5");
        requestDispatcher.forward(req,resp);
    }
}
